package com.lcxw.hxzbapi.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lcxw.hxzbapi.dao.mapper.SvCommentLikeMapper;
import com.lcxw.hxzbapi.entity.pojo.SvCommentLike;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class SvCommentLikeService {

    @Resource
    SvCommentLikeMapper svCommentLikeMapper;

    //新增短视频的评论点赞
    public int insert(SvCommentLike svCommentLike) {
        return svCommentLikeMapper.insert(svCommentLike);
    }

    //删除一个短视频评论点赞
    public int delete(int likeId) {
        UpdateWrapper<SvCommentLike> wrapper = new UpdateWrapper<>();
        wrapper.eq("likeId", likeId);
        return svCommentLikeMapper.delete(wrapper);
    }

    //获取一个短视频点赞bean
    public SvCommentLike selectOne(int commentId, long userId) {
        QueryWrapper<SvCommentLike> wrapper = new QueryWrapper<>();
        wrapper.eq("commentId", commentId);
        wrapper.eq("userId", userId);
        return svCommentLikeMapper.selectOne(wrapper);
    }

    //获取一条评论的点赞量
    public int getLikes(int commentId) {
        QueryWrapper<SvCommentLike> wrapper = new QueryWrapper<>();
        wrapper.eq("commentId", commentId);
        return svCommentLikeMapper.selectCount(wrapper);
    }

    //获取是否点赞
    public int getIsLike(int commentId, long userId) {
        return svCommentLikeMapper.getIsLike(commentId, userId);
    }
}
